package 观察者模式例子;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lilei on 2016/3/17.
 * 具体主题
 */
public class BossDo implements BossAction {
    private String sth;
    private List<BossListener> listeners = new ArrayList<BossListener>();

    public String getSth() {
        return sth;
    }

    public void setSth(String sth) {
        this.sth = sth;
    }


    @Override
    public void registerListener(BossListener bossListener) {
        listeners.add(bossListener);
    }

    @Override
    public void removeListener(BossListener bossListener) {
        listeners.remove(bossListener);
    }

    @Override
    public void notifyAllpeople() {
        for(BossListener bossListener : listeners) {
            bossListener.informWorkers(this);
        }
    }

    @Override
    public void doWhat() {
        System.out.println(sth);
    }

    public static void main(String[] args) {
        BossDo bossDo = new BossDo();
        BossListener bossListener = new BossListenerImpl();
        bossDo.registerListener(bossListener);
        bossDo.setSth("boss coming back!");
//        bossDo.setSth("boss going out!");
        bossDo.notifyAllpeople();



    }
}
